#!/usr/bin/python
# -*- coding:utf-8 -*-
# @author  : micah
# @time    :  
# @function: 
# @version :


import time, random, os
from multiprocessing import Queue, Process


def func_write(q):
    for value in [1, 2, 3]:
        q.put(value)
        time.sleep(random.random())


def func_read(q):
    print(os.getpid(), os.getppid())
    while True:
        if not q.empty():
            val = q.get()
            print(val)
        else:
            break


if __name__ == '__main__':
    q = Queue()
    obj_write = Process(target=func_write, args=(q,))
    obj_read = Process(target=func_read, args=(q,))

    obj_write.start()
    obj_write.join()

    obj_read.start()
    obj_read.join()

    print(obj_read.is_alive())
    print('主进程即将退出...')
